/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shootanddestroy;

import net.phys2d.raw.*;
import net.phys2d.raw.test.*;
import net.phys2d.raw.shapes.*;
import net.phys2d.math.Vector2f;

/**
 *
 * @author wida46412464
 */
public class Prova extends AbstractDemo {

    private Body b2;
    private float x = 0;
    private float y = 0;
    private Body linia;
    private Body bola;
    private boolean render;

    public Prova() {
        super("Proves");
    }

    @Override
    public void keyHit(char c) {
        super.keyHit(c);

        if (c == 'q') {
            if (y > -200000) {
                y -= 10000;
            }
            System.out.println("Valor de y:" + y);
        }

        if (c == 'w') {
            if (y < 200000) {
            y += 10000;
            }
            System.out.println("Valor de y:" + y);
        }

        if (c == 'a') {
            if (x < 200000) {
                x += 10000;
            }
            System.out.println("Valor de x:" + x);
        }

        if (c == 's') {
            if (x > -200000) {
                x -= 10000;
            }
            System.out.println("Valor de x:" + x);
        }

        if (c == ' ') {
            render = false;
            world.remove(linia);
            b2.setGravityEffected(true);
            b2.addForce(new Vector2f(x, y));
        }
    }

    protected void init(World world) {
        render  = true;
        x = 0;
        y = 0;
        Body body1 = new StaticBody("Ground1", new Box(600.0f, 10.0f));
        body1.setPosition(250.0f, 400);
        world.add(body1);

        DynamicShape shape = new Circle(10);
        bola = new Body(shape, 50.0f);
        bola.setFriction(0.4f);
        bola.setPosition(100.0f, 350);
        bola.setRotation(0.0f);
        b2 = bola;
        b2.setGravityEffected(false);
        world.add(bola);

        linia = new Body("Mover1", new Line(new Vector2f(100.0f, 350), new Vector2f(100.0f, 350)), 100.0f);
        linia.setGravityEffected(false);
        linia.addExcludedBody(bola);
        world.add(linia);

        Body body2 = new Body("Mover1", new Box(15.0f, 100.0f), 100.0f);
        body2.setPosition(450.0f, 350);
        world.add(body2);

        Body body3 = new Body("Mover1", new Box(15.0f, 100.0f), 100.0f);
        body3.setPosition(350.0f, 350);
        world.add(body3);

        Body body4 = new Body("Mover1", new Box(120.0f, 15.0f), 100.0f);
        body4.setPosition(400.0f, 288);
        world.add(body4);

        Body body5 = new Body("Mover1", new Box(15.0f, 100.0f), 100.0f);
        body5.setPosition(400.0f, 230);
        world.add(body5);

    }

    public static void main(String[] argv) {
        Prova prova = new Prova();
        prova.start();
    }

    @Override
    public void update() {
        if (render) {
            world.remove(linia);
            Line aux = new Line(new Vector2f(100.0f, 350), new Vector2f(100.0f + x / 5000, 350 + y / 5000));
            linia = new Body("Mover1", aux, 100.0f);
            linia.setGravityEffected(false);
            linia.addExcludedBody(bola);
            world.add(linia);
        }
    }
}
